#!/bin/bash
# Version 8

startDir=$PWD


### Translations
if [ -d "package/translate" ]; then
	echo "[build] translate dir found, running merge."
	(cd package/translate && sh ./merge && sh ./build)
	if [ "$(git diff --stat .)" != "" ]; then
		echo "[build] Changed detected. Cancelling build."
		git diff --stat .
		# exit
	fi
fi


### Variables
packageNamespace=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Name")
packageName="${packageNamespace##*.}" # Strip namespace (Eg: "org.kde.plasma.")
packageVersion=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Version")
packageAuthor=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Author")
packageAuthorEmail=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Email")
packageWebsite=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="X-KDE-PluginInfo-Website")
packageComment=$(kreadconfig5 --file="$PWD/package/metadata.desktop" --group="Desktop Entry" --key="Comment")


### *.plasmoid
filenameTag="-plasma5.12"
filename="${packageName}-v${packageVersion}${filenameTag}.plasmoid"
rm ${packageName}-v*.plasmoid # Cleanup
(cd package \
	&& zip -r $filename * \
	&& mv $filename $startDir/$filename \
)
cd $startDir
echo "[plasmoid] md5: $(md5sum $filename | awk '{ print $1 }')"
echo "[plasmoid] sha256: $(sha256sum $filename | awk '{ print $1 }')"


### Done
cd $startDir

